﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;

namespace LdCms.BLL.Community
{
    using LdCms.EF.DbEntitiesContext;
    using LdCms.EF.DbModels;
    using LdCms.EF.DbStoredProcedure;
    using LdCms.IBLL.Community;
    using LdCms.IDAL.Community;
    using LdCms.Common.Json;
    using LdCms.Common.Security;
    using LdCms.Common.Extension;
    using LdCms.Common.Enum;
    using LdCms.Common.Net;
    public partial class ThemeCollectService : BaseService<Ld_Community_ThemeCollect>, IThemeCollectService
    {
        private readonly IThemeCollectDAL ThemeCollectDAL;
        private readonly LdCmsDbEntitiesContext LdCmsDbEntitiesContext;
        public ThemeCollectService(LdCmsDbEntitiesContext LdCmsDbEntitiesContext, IThemeCollectDAL ThemeCollectDAL)
        {
            this.LdCmsDbEntitiesContext = LdCmsDbEntitiesContext;
            this.ThemeCollectDAL = ThemeCollectDAL;
            this.Dal = ThemeCollectDAL;
        }
        public override void SetDal()
        {
            Dal = ThemeCollectDAL;
        }

        public bool IsExists(int systemId, string companyId, string memberId, string themeId)
        {
            try
            {
                var expression = ExtLinq.True<Ld_Community_ThemeCollect>();
                expression = expression.And(m => m.SystemID == systemId && m.CompanyID == companyId && m.MemberID == memberId && m.ThemeID == themeId);
                return IsExists(expression);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        public bool SaveThemeCollect(int systemId, string companyId, string memberId, string themeId)
        {
            try
            {
                var verify = IsExists(systemId, companyId, memberId, themeId);
                if (verify)
                    throw new Exception("已收藏！");
                var entity = new Ld_Community_ThemeCollect()
                {
                    SystemID = systemId,
                    CompanyID = companyId,
                    MemberID = memberId,
                    ThemeID = themeId,
                    IpAddress = Net.Ip,
                    State = true,
                    CreateDate = DateTime.Now
                };
                return Add(entity);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        public bool DeleteThemeCollect(int systemId, string companyId, string memberId, string themeId)
        {
            try
            {
                var expression = ExtLinq.True<Ld_Community_ThemeCollect>();
                expression = expression.And(m => m.SystemID == systemId && m.CompanyID == companyId && m.MemberID == memberId && m.ThemeID == themeId);
                return Delete(expression);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        public Ld_Community_ThemeCollect GetThemeCollect(int systemId, string companyId, string memberId, string themeId)
        {
            try
            {
                var expression = ExtLinq.True<Ld_Community_ThemeCollect>();
                expression = expression.And(m => m.SystemID == systemId && m.CompanyID == companyId && m.MemberID == memberId && m.ThemeID == themeId);
                return Find(expression);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }



    }
}
